//
//  HelpMeDoCell.m
//  MRBang
//
//  Created by 铅笔 on 15/12/16.
//  Copyright © 2015年 杭州易网新科技. All rights reserved.
//

#import "HelpMeDoCell.h"
#import "HelpMeDoModel.h"

@interface HelpMeDoCell ()

@property (nonatomic,strong) UIView *view_topBG;
@property (nonatomic,strong) UIView *view_buttomBG;

@property (nonatomic,strong) UIImageView *imageView_icon;
@property (nonatomic,strong) UILabel *label_peopleAmount;//人数
@property (nonatomic,strong) UILabel *label_applyStatus;//申请状态
@property (nonatomic,strong) UIImageView *imageView_arrowRight;//右侧按钮

@property (nonatomic,strong) UILabel *label_buttomTop;
@property (nonatomic,strong) UILabel *label_buttomButtom;

@end

@implementation HelpMeDoCell

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initWithSubviews];
    }
    
    return self;
}

#pragma mark --- 创建视图
- (void) initWithSubviews
{
   
    // 头部
    self.view_topBG = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 147*PROPORTION_WIDTH)];
    [self addSubview:self.view_topBG];
    
    //imageview
    self.imageView_icon = [[UIImageView alloc] initWithFrame:CGRectMake(10, 25, 365*PROPORTION_WIDTH, 56*PROPORTION_WIDTH)];
    [self.view_topBG addSubview:self.imageView_icon];
    self.imageView_icon.layer.cornerRadius = 5.0;
    self.imageView_icon.clipsToBounds = YES;
    
    //箭头
    self.imageView_arrowRight = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth-30, self.view_topBG.frame.size.height/2-10, 20, 20)];
    [self.view_topBG addSubview:self.imageView_arrowRight];
    self.imageView_arrowRight.image = [UIImage imageNamed:@"return_right"];
    
    //人数
    self.label_peopleAmount = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth-160, 45*PROPORTION_WIDTH, kScreenWidth/3-10, 20)];
    [self.view_topBG addSubview:self.self.label_peopleAmount];
    self.label_peopleAmount.textAlignment = NSTextAlignmentRight;
//    self.label_peopleAmount.backgroundColor = [UIColor redColor];
    
    //状态
    self.label_applyStatus = [[UILabel alloc] initWithFrame:CGRectMake(self.label_peopleAmount.x, self.label_peopleAmount.bottom+10*PROPORTION_WIDTH, kScreenWidth/3, 20)];
    [self.view_topBG addSubview:self.self.label_applyStatus];
    
    self.label_applyStatus.textAlignment = NSTextAlignmentRight;
    self.label_applyStatus.textColor = RXDColor(132, 132, 132);
    self.label_applyStatus.font = [UIFont systemFontOfSize:Font_SIZE_22];
    self.label_applyStatus.textAlignment = NSTextAlignmentRight;

    //底部
    [self initWithButtomSubviews];
}

- (void) initWithButtomSubviews
{
    self.view_buttomBG = [[UIView alloc] initWithFrame:CGRectMake(0,self.view_topBG.frame.size.height, kScreenWidth, 134*PROPORTION_WIDTH)];
    [self addSubview:self.view_buttomBG];
    

    //横线
    UIView *view_line  = [[UIView alloc] initWithFrame:CGRectMake(0,0,kScreenWidth,1.0)];
    [self.view_buttomBG addSubview:view_line];
    view_line.backgroundColor = RXDColor(243, 245, 246);
    
    for (int i=0; i<2; i++) {
        CGFloat view_lineX = kScreenWidth/3;
        UIView *view_line  = [[UIView alloc] initWithFrame:CGRectMake(view_lineX*(i+1),0,1.0,116*PROPORTION_WIDTH)];
        [self.view_buttomBG addSubview:view_line];
        view_line.backgroundColor = RXDColor(243, 245, 246);
    }
    
    //横线
    UIView *view_lineButtom  = [[UIView alloc] initWithFrame:CGRectMake(0,self.view_buttomBG.height-20*PROPORTION_WIDTH,kScreenWidth,20.0*PROPORTION_WIDTH)];
    [self.view_buttomBG addSubview:view_lineButtom];
    view_lineButtom.backgroundColor = RXDColor(243, 245, 246);
    
    
    
    NSArray *array_titleTop = @[@"2千－5万元",@"100%",@"7-15个工作日"];
    NSArray *array_title = @[@"额度",@"成功率",@"申请周期"];
    
    for (int i=0; i<3; i++) {
        
        CGFloat labelX = kScreenWidth/3;
        self.label_buttomTop = [[UILabel alloc] initWithFrame:CGRectMake(labelX*i, 26*PROPORTION_WIDTH, kScreenWidth/3, 26*PROPORTION_WIDTH)];
        [self.view_buttomBG addSubview:self.label_buttomTop];
        self.label_buttomTop.text = array_titleTop[i];
        self.label_buttomTop.textAlignment = NSTextAlignmentCenter;
        self.label_buttomTop.font = [UIFont systemFontOfSize:Font_SIZE_22];
        
        if (i!=2) {
            self.label_buttomTop.textColor = [UIColor redColor];
        }
        
        self.label_buttomButtom = [[UILabel alloc] initWithFrame:CGRectMake(labelX*i,self.label_buttomTop.bottom+10*PROPORTION_WIDTH, kScreenWidth/3, 26*PROPORTION_WIDTH)];
        [self.view_buttomBG addSubview:self.label_buttomButtom];
        self.label_buttomButtom.text = array_title[i];
        self.label_buttomButtom.textAlignment = NSTextAlignmentCenter;
        self.label_buttomButtom.font = [UIFont systemFontOfSize:Font_SIZE_22];
        self.label_buttomButtom.textColor = RXDColor(132, 132, 132);
        
    }
    
}

- (void) layoutSubviews
{
    
    if (self.model_helpMe.img.length==0) {

        [self.imageView_icon sd_setImageWithURL:nil placeholderImage:nil];
    }
    else
    {
        NSRange range = [self.model_helpMe.img rangeOfString:@"<"];
        NSString *strImageURL = [self.model_helpMe.img substringToIndex:range.location];
    
        [self.imageView_icon sd_setImageWithURL:[NSURL URLWithString:strImageURL] placeholderImage:nil];
    }
    
     self.label_applyStatus.text = @"已通过申请";
    
    self.label_peopleAmount.text = [NSString stringWithFormat:@"%@人",self.model_helpMe.successscount];
    self.label_peopleAmount.font = [UIFont systemFontOfSize:Font_SIZE_24];
    
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:self.label_peopleAmount.text];
    
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:14.0]
     
                          range:NSMakeRange(0,self.label_peopleAmount.text.length)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:RXDColor(132, 132, 132)
     
                          range:NSMakeRange(self.label_peopleAmount.text.length-1,1)];
    
    self.label_peopleAmount.attributedText = AttributedStr;

}
@end
